// 常用的uni api封装，方便在页面中直接使用
import { useUserStore } from "@/store/user"

export const showModal = options => {
  uni.showModal({
    ...options,
    confirmColor: '#F4AF22',
  })
}

export function showToast(msg, icon = 'success') {
  uni.showToast({
    icon: msg.length >= 6 ? 'none': icon,
    title: msg
  })
}

export function navigate(url, authLogin = false) {
  if (authLogin && !useUserStore().isLogin) {
    uni.navigateTo({
      url: '/package_user/pages/common/login'
    })
  } else {
    uni.navigateTo({ url })
  }
}

export function switchTab(url, authLogin = false) {
  if (authLogin && !useUserStore().isLogin) {
    uni.switchTab({
      url: '/package_user/pages/common/login'
    })
  } else {
    uni.switchTab({ url })
  }
}

export function redirectTo(url, authLogin = false) {
  if (authLogin && !useUserStore().isLogin) {
    uni.navigateTo({
      url: '/package_user/pages/common/login'
    })
  } else {
    uni.redirectTo({ url })
  }
}

export function navigateBack(delta = 1) {
  uni.navigateBack({
    delta: delta
  })
}

export function previewImage(urls, current) {
  uni.previewImage({
    urls,
    current
  })
}

export function callPhone(number) {
  uni.makePhoneCall({
    phoneNumber: number
  })
}

export function copyText(text) {
  uni.setClipboardData({
    data: text
  })
}